//package com.teach.service.impl.photo;
//
//import java.awt.image.BufferedImage;
//import java.io.File;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.List;
//
//import javax.imageio.ImageIO;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cache.annotation.Cacheable;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.teach.commons.FileUtil;
//import com.teach.commons.Id;
//import com.teach.dto.LoginUser;
//import com.teach.dto.PhotoFormDTO;
//import com.teach.dto.PhotoPicSearch;
//import com.teach.dto.PhotoPopularAuthorDTO;
//import com.teach.entity.PhotoPic;
//import com.teach.exception.CodeException;
//import com.teach.mapper.PhotoPicMapper;
//import com.teach.service.FileService;
//import com.teach.service.photo.PhotoPicService;
//
//import net.coobird.thumbnailator.Thumbnails;
//import net.coobird.thumbnailator.geometry.Positions;
//
//@Service
//public class PhotoPicServiceImpl2 implements PhotoPicService{
//
//	@Autowired
//	private PhotoPicMapper mapper;
//	
//	@Autowired
//	private FileService fileService;
//	
//	@Autowired
//	private Id id;
//	
//	@Override
//	public int deleteByPrimaryKey(Long photoPicId) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//
//	@Override
//	public int insert(PhotoPic record) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//
//	@Override
//	public int insertSelective(LoginUser user, PhotoFormDTO form,MultipartFile img) {
//		Long ids = id.nextId();
//		String uri = "photo/" + new SimpleDateFormat("yyyy/MM/dd/").format(new Date()) + ids + "/";
//		//File path = new File(root, uri);
//		path.mkdirs();
//
//		// 保存原始图片
//		//File file = new File(path, "1." + FileUtil.getFileExt(img.getOriginalFilename()));
//		try {
//			img.transferTo(file);
//		} catch (Exception e) {
//			throw new CodeException(100);
//		}
//		
//		// 生成缩略图
//		BufferedImage i = null;
//		try {
//			i = ImageIO.read(file);
//			Thumbnails.of(i).size(100, 100).outputFormat("png").toFile(new File(path, "2.png"));
//		} catch (Exception e) {
//			throw new CodeException(101);
//		}
//		
//		// 生成加水印大图
//		try {
//			BufferedImage image = ImageIO.read(new File(root, "_w.png"));
//			Thumbnails.of(i).size(800, 800).watermark(Positions.CENTER, image, 1).outputFormat("png")
//					.toFile(new File(path, "3.png"));
//		} catch (Exception e) {
//			throw new CodeException(102);
//		}
//		
//		PhotoPic photoPic = new PhotoPic();
//		//存储路径
//		photoPic.setPhotoThumbnailPicPath(String.format("%s1.%s", uri, FileUtil.getFileExt(img.getOriginalFilename())));
//		photoPic.setPhotoWatermarkPicPath(String.format("%s2.png", uri));
//		photoPic.setPhotoOriginalPicPath(String.format("%s3.png", uri));
//		
//		//作者用户名
//		photoPic.setPhotoWriterId(user.getUserName());
//		
//		photoPic.setPhotoPicClassId(form.getAlbumId());
//		photoPic.setPhotoPicTitle(form.getPhotoName());
//		if(!StringUtils.isEmpty(form.getPhotoMemo())) {
//			photoPic.setPhotoPicRemark(form.getPhotoMemo());
//		}
//		
//		photoPic.setPhotoReleaseTime(new Date());
//		photoPic.setPhotoPicStatus("1");
//		
//		return mapper.insertSelective(photoPic);
//	}
//
//	@Override
//	public PhotoPic selectByPrimaryKey(Long photoPicId) {
//		// TODO Auto-generated method stub
//		return mapper.selectByPrimaryKey(photoPicId);
//	}
//
//	@Override
//	public int updateByPrimaryKeySelective(PhotoPic record) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//
//	@Override
//	public int updateByPrimaryKey(PhotoPic record) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//
//	@Override
//	public List<PhotoPic> selectAll(int index,int len) {
//		// TODO Auto-generated method stub
//		return mapper.selectAll(index, len);
//	}
//
//	@Override
//	public List<PhotoPic> selectGreatDESC() {
//		// TODO Auto-generated method stub
//		return mapper.selectGreatDESC();
//	}
//
//	
//	@Override
//	public List<PhotoPic> selectPicDetails(String title, String writerId, Long picClassId) {
//		 return mapper.selectPicDetails(title, writerId, picClassId);
//	}
//	
//	@Cacheable(value = "PhotoPicService", key = "'selectByWriterId' + #photoWriterId")
//	@Override
//	public List<PhotoPic> selectByWriterId(String photoWriterId) {
//		return mapper.selectByWriterId(photoWriterId);
//	}
//
//	@Override
//	public Long selectPicTitle(String photoPicTitle) {
//		// TODO Auto-generated method stub
//		return mapper.selectPicTitle(photoPicTitle);
//	}
//
//	@Override
//	public PhotoPopularAuthorDTO  selectPopularAuthor(String photoReleaseTime,String userName) {
//		// TODO Auto-generated method stub
//		return mapper.selectPopularAuthor(photoReleaseTime, userName);
//	}
//
//	@Override
//	public Integer selectWorksCount(String photoReleaseTime, String userName) {
//		// TODO Auto-generated method stub
//		return mapper.selectWorksCount(photoReleaseTime, userName);
//	}
//
//	@Override
//	public PhotoPic selectPicDetailsDESC(String title, String writerId, Long picClassId) {
//		// TODO Auto-generated method stub
//		return mapper.selectPicDetailsDESC(title, writerId, picClassId);
//	}
//
//	@Override
//	public List<PhotoPic> selectType(Long picClassId) {
//		// TODO Auto-generated method stub
//		return mapper.selectType(picClassId);
//	}
//	
//	@Override
//	public PageInfo<PhotoPic> pageSearch(PhotoPicSearch search) {
//		return PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->mapper.pageSearch(search));
//	}
//
//	@Override
//	public PhotoPopularAuthorDTO selectAuthorInfo(String userName) {
//		// TODO Auto-generated method stub
//		return mapper.selectAuthorInfo(userName);
//	}
//	
//}
